* Set Directory
clear
set more off

cd "$path"
global working_data "$path/data"
global out_files "$path/output"

********************************************************************************
* Create sample 1 for main regression analysis
********************************************************************************
clear
use $working_data/SHARE_JOLE_replication.dta, clear

keep if inrange(ragey, 50, 70) // only keep individuals aged 50-70

*ERA in years
gen group_eray = round(era_months/12, 1.0)

*Define artificial never treated group:
gen group_eray_never = group_eray
replace group_eray_never = 0 if group_eray==63 | group_eray==64

save "$working_data/sample1.dta", replace	

********************************************************************************
* Create sample 2 for analysis of retirement from employment
********************************************************************************
clear
use $working_data/SHARE_JOLE_replication.dta, clear

keep if inrange(ragey, 50, 70) // only keep individuals aged 50-70

*Define retirement as an absorbing state
bysort nmergeid (wave): gen d_check = 1 if c_lms_new[_n]!=1 & c_lms_new[_n-1]==1 & _n>1
tab isocountry d_check

gen d_check_wave = wave if d_check==1
bysort nmergeid (wave): egen min_d_check_wave=min(d_check_wave)

bysort nmergeid (wave): gen d_check_absorb = 1 if wave>=min_d_check_wave

gen c_lms_new_absorb=c_lms_new
replace c_lms_new_absorb=1 if d_check_absorb==1

tab c_lms_new_absorb c_lms_new

keep if c_lms_new_absorb==1 | c_lms_new_absorb==2 // keep retired and employed individuals only according to newly constructed variable

*Define retirement outcome
tab c_lms_new_absorb
gen retired = 0 if c_lms_new_absorb!=.
replace retired=1 if c_lms_new_absorb==1

*ERA in years
gen group_eray = round(era_months/12, 1.0)

*Define artificial never treated group:
gen group_eray_never = group_eray
replace group_eray_never = 0 if group_eray==63 | group_eray==64
		
save "$working_data/sample2.dta", replace


********************************************************************************
* Table 2: Estimated effects of reaching the Early Retirement Age (ERA) on retirement and self- reported retirement for men
********************************************************************************
use "$working_data/sample2.dta", clear

eststo clear
jwdid retired if ragey<63 & ragender==1, ivar(nmergeid) tvar(ragey) gvar(group_eray) hettype(twfe) fevar(riwm) 
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A

jwdid retired if ragey<63 & ragender==1, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm) 
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo B

jwdid retired if ragey<63 & ragender==1, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm) 
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C

esttab A B C using "$out_files/Table2a.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA")

use "$working_data/sample1.dta", clear
gen self_retire = self_lf == 5

jwdid self_retire if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) hettype(twfe) fevar(riwm) 
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A

jwdid self_retire if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm) 
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo B

jwdid self_retire if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm) 
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C

esttab A B C using "$out_files/Table2b.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA")


********************************************************************************
* Table 3: Estimated effects of reaching the Early Retirement Age (ERA) on the mental well-being of men
********************************************************************************
use "$working_data/sample1.dta", clear

bys nmergeid: egen tot = count(nmergeid)
gen emp = c_lms_new==2
bys nmergeid: egen tot_emp = sum(emp)
drop if tot_emp ~= tot & emp

eststo clear
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm) hettype(twfe)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo A
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: A
estadd matrix r_p1: A

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo B
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: B
estadd matrix r_p1: B

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo C
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: C
estadd matrix r_p1: C

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo D
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: D
estadd matrix r_p1: D

qui jwdid depression emp if ragey<63 & ragender==1 & (c_lms_new==2|c_lms_new==3), ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.91 0.75)) noestimcheck contrast(atcontrast(r)) post
eststo E
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
qui jwdid depression emp if ragey<63 & ragender==1 & (c_lms_new==2|c_lms_new==3), ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.91 0.75)) noestimcheck contrast(atcontrast(r)) post
matrix table1 = r(table)
matrix r_se1 = table1[2,2...]
matrix r_p1 = table1[4,2...]
estadd matrix r_se1: E
estadd matrix r_p1: E

esttab A B C D E using "$out_files/Table3a.tex", replace b(a2) se(a2) keep(r3vs1._at) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(r3vs1._at "ERA") cell(b(fmt(a2) star pvalue(r_p1)) r_se1(par)) collabels(none)

eststo clear
qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm) hettype(twfe)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo A
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: A
estadd matrix r_p1: A

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo B
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: B
estadd matrix r_p1: B

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo C
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: C
estadd matrix r_p1: C

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo D
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: D
estadd matrix r_p1: D

qui jwdid reurod emp if ragey<63 & ragender==1 & (c_lms_new==2|c_lms_new==3), ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.91 0.75)) noestimcheck contrast(atcontrast(r)) post
eststo E
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
qui jwdid reurod emp if ragey<63 & ragender==1 & (c_lms_new==2|c_lms_new==3), ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.91 0.75)) noestimcheck contrast(atcontrast(r)) post
matrix table1 = r(table)
matrix r_se1 = table1[2,2...]
matrix r_p1 = table1[4,2...]
estadd matrix r_se1: E
estadd matrix r_p1: E

esttab A B C D E using "$out_files/Table3b.tex", replace b(a2) se(a2) keep(r3vs1._at) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(r3vs1._at "ERA") cell(b(fmt(a2) star pvalue(r_p1)) r_se1(par)) collabels(none)


********************************************************************************
* Figure 2: Event studies for men
********************************************************************************
use "$working_data/sample2.dta", clear

capture program drop prepare_plot
program define prepare_plot
	qui:sum `e(tvar)' if e(sample), meanonly
	qui:gen __event__ = `e(tvar)'-`e(gvar)' if `e(gvar)'!=0 & e(sample) 
	qui:replace __event__=1+__event__+12
	replace __event__ = 10 if __event__ == 11
	replace __event__ = 8 if __event__ == 9
	replace __event__ = 6 if __event__ == 7
	replace __event__ = 4 if __event__ == 5
	replace __event__ = 2 if __event__ == 3
	replace __event__ = 2 if __event__ == 1
	replace __event__ = 14 if __event__ == 13
	replace __event__ = 16 if __event__ == 15
	replace __event__ = 18 if __event__ == 17
	replace __event__ = 20 if __event__ == 19
	replace __event__ = 20 if __event__ == 21
	margins, subpop(if __tr__!=0) at(__tr__=(0 1)) over(__event__) noestimcheck contrast(atcontrast(r)) post

end	

*Panel (a)
capture drop __*
jwdid retired if ragey<63 & ragender==1, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-.2 .8)) ylab(-.2(.2).8) scale(1.3)
graph export "$out_files/retired.pdf", replace

use "$working_data/sample1.dta", clear

bys nmergeid: egen tot = count(nmergeid)
gen emp = c_lms_new==2
bys nmergeid: egen tot_emp = sum(emp)
drop if tot_emp ~= tot & emp

*Panel (b)
gen self_retire = self_lf == 5
capture drop __*
jwdid self_retire if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-.2 .8)) ylab(-.2(.2).8) scale(1.3)
graph export "$out_files/retired-self.pdf", replace

*Panel (c)		
capture drop __*
jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-0.8 .4)) ylab(-0.8(.4).4) scale(1.3)
graph export "$out_files/depression.pdf", replace

*Panel (d)
capture drop __*
jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-3 1.5)) ylab(-3(1.5)1.5) scale(1.3)
graph export "$out_files/euro-d.pdf", replace

use "$working_data/sample1.dta", clear

bys nmergeid: egen tot = count(nmergeid)
gen emp = c_lms_new==2
bys nmergeid: egen tot_emp = sum(emp)
drop if tot_emp ~= tot & emp 

*Panel (e)
capture drop __*
jwdid depression if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-0.8 .4)) ylab(-0.8(.4).4) scale(1.3)
graph export "$out_files/depression-e.pdf", replace

*Panel (f)
capture drop __*
jwdid reurod if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-3 1.5)) ylab(-3(1.5)1.5) scale(1.3)
graph export "$out_files/euro-d-e.pdf", replace



********************************************************************************
* Table C.1 and Figure C.2: Disabled men
********************************************************************************
* Table C.1: Estimated effects of reaching the Early Retirement Age (ERA) on the mental well-being of disabled men
eststo clear
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==4, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==4, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo B

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==4, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==4, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo D

esttab A B C D using "$out_files/AppendixTableC1.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA")

*Figure C.2: Event studies - Disabled men
capture drop __*
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==4, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7")
graph export "$out_files/depression-d.pdf", replace

capture drop __*
qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==4, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7")
graph export "$out_files/eur-d-d.pdf", replace

********************************************************************************
* Table C.2 and Figure C.4: Women
********************************************************************************
*Table C.2: Estimated effects of reaching the Early Retirement Age (ERA) on the mental well-being of women
eststo clear
qui jwdid depression if ragey<63 & ragender==2 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo A

qui jwdid reurod if ragey<63 & ragender==2 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo B

qui jwdid depression if ragey<63 & ragender==2 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo C

qui jwdid reurod if ragey<63 & ragender==2 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo D

qui jwdid depression emp if ragey<63 & ragender==2 & (c_lms_new==2|c_lms_new==3), ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.78 0.89)) noestimcheck contrast(atcontrast(r)) post
eststo E
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
qui jwdid depression emp if ragey<63 & ragender==2 & (c_lms_new==2|c_lms_new==3), ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.78 0.89)) noestimcheck contrast(atcontrast(r)) post
matrix table1 = r(table)
matrix r_se1 = table1[2,2...]
matrix r_p1 = table1[4,2...]
estadd matrix r_se1: E
estadd matrix r_p1: E

qui jwdid reurod emp if ragey<63 & ragender==2 & (c_lms_new==2|c_lms_new==3), ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.78 0.89)) noestimcheck contrast(atcontrast(r)) post
eststo F
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
qui jwdid reurod emp if ragey<63 & ragender==2 & (c_lms_new==2|c_lms_new==3), ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.78 0.89)) noestimcheck contrast(atcontrast(r)) post
matrix table1 = r(table)
matrix r_se1 = table1[2,2...]
matrix r_p1 = table1[4,2...]
estadd matrix r_se1: F
estadd matrix r_p1: F

esttab A B C D E F using "$out_files/AppendixTableC2a.tex", replace b(a2) se(a2) keep(r3vs1._at) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01)  coeflabels(r3vs1._at "ERA")

eststo clear
qui jwdid depression if ragey<63 & ragender==2 & c_lms_new==3 & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo A

qui jwdid reurod if ragey<63 & ragender==2 & c_lms_new==3 & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo B

qui jwdid depression if ragey<63 & ragender==2 & c_lms_new==2 & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo C

qui jwdid reurod if ragey<63 & ragender==2 & c_lms_new==2 & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo D

qui jwdid depression emp if ragey<63 & ragender==2 & (c_lms_new==2|c_lms_new==3) & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.95 0.67)) noestimcheck contrast(atcontrast(r)) post
eststo E
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
qui jwdid depression emp if ragey<63 & ragender==2 & (c_lms_new==2|c_lms_new==3) & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.95 0.67)) noestimcheck contrast(atcontrast(r)) post
matrix table1 = r(table)
matrix r_se1 = table1[2,2...]
matrix r_p1 = table1[4,2...]
estadd matrix r_se1: E
estadd matrix r_p1: E

qui jwdid reurod emp if ragey<63 & ragender==2 & (c_lms_new==2|c_lms_new==3) & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.95 0.67)) noestimcheck contrast(atcontrast(r)) post
eststo F
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
qui jwdid reurod emp if ragey<63 & ragender==2 & (c_lms_new==2|c_lms_new==3) & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
margins, subpop(if __etr__==1) at(__tr__=(0 1) _x_emp= (-.95 0.67)) noestimcheck contrast(atcontrast(r)) post
matrix table1 = r(table)
matrix r_se1 = table1[2,2...]
matrix r_p1 = table1[4,2...]
estadd matrix r_se1: F
estadd matrix r_p1: F

esttab A B C D E F using "$out_files/AppendixTableC2b.tex", replace b(a2) se(a2) keep(r3vs1._at) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01)  coeflabels(r3vs1._at "ERA")

*Figure C.4: Event studies for women
use "$working_data/sample2.dta", clear

*Panel (a)
capture drop __*
jwdid retired if ragey<63 & ragender==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-.2 .8)) ylab(-.2(.2).8) scale(1.3)
graph export "$out_files/retired-f.pdf", replace

use "$working_data/sample1.dta", clear

bys nmergeid: egen tot = count(nmergeid)
gen emp = c_lms_new==2
bys nmergeid: egen tot_emp = sum(emp)
drop if tot_emp ~= tot & emp 

*Panel (b)
gen self_retire = self_lf == 5
capture drop __*
jwdid self_retire if ragey<63 & ragender==2 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-.2 .8)) ylab(-.2(.2).8) scale(1.3)
graph export "$out_files/retired-self-f.pdf", replace

*Panel (c)
capture drop __*
qui jwdid depression if ragey<63 & ragender==2 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-0.8 .4)) ylab(-0.8(.4).4) scale(1.3)
graph export "$out_files/depression-f.pdf", replace

*Panel (d)
capture drop __*
qui jwdid reurod if ragey<63 & ragender==2 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-3 1.5)) ylab(-3(1.5)1.5) scale(1.3)
graph export "$out_files/euro-d-f.pdf", replace

*Panel (e)
capture drop __*
qui jwdid depression if ragey<63 & ragender==2 & c_lms_new==3 & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-0.8 .4)) ylab(-0.8(.4).4) scale(1.3)
graph export "$out_files/depression-f-noh.pdf", replace

*Panel (f)
capture drop __*
qui jwdid reurod if ragey<63 & ragender==2 & c_lms_new==3 & self_lf~=8, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-3 1.5)) ylab(-3(1.5)1.5) scale(1.3)
graph export "$out_files/euro-d-f-noh.pdf", replace

*Panel (g)
capture drop __*
qui jwdid depression if ragey<63 & ragender==2 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-0.8 .4)) ylab(-0.8(.4).4) scale(1.3)
graph export "$out_files/depression-e-f.pdf", replace

*Panel (h)
capture drop __*
qui jwdid reurod if ragey<63 & ragender==2 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-3 1.5)) ylab(-3(1.5)1.5) scale(1.3)
graph export "$out_files/euro-d-e-f.pdf", replace


********************************************************************************
* Figure D.1 and Table D.1: government transfers of unemployed men
********************************************************************************
clear 
use "$working_data/H_SHARE_d.dta"

matrix cpi = J(13,10,.)
matrix list cpi

local col = 1
foreach c in 40 56 208 250 276 380 528 724 752 756 {

forvalues y=2003(1)2015{

sum c`y'cpindex if isocountry==`c'
matrix cpi[`y'-2002,`col'] = r(mean)

}

local col = `col' + 1
}

matrix list cpi

* Figure D.1: Event studies for government transfers of unemployed men
use "$working_data/sample1.dta", clear

bys nmergeid: egen tot = count(nmergeid)
gen emp = c_lms_new==2
bys nmergeid: egen tot_emp = sum(emp)
drop if tot_emp ~= tot & emp


gen ritgxfr_cpi=. // government transfers adjusted for consumer price index (CPI)

local col = 1
foreach c in 40 56 208 250 276 380 528 724 752 756 {

forvalues y=2003(1)2015{

scalar s_cpi = cpi[`y'-2002,`col']
replace ritgxfr_cpi = ritgxfr / s_cpi * 100 if isocountry==`c' & year==`y' 
scalar list
}

local col = `col' + 1
}

gen d_ritgxfr = ritgxfr!=0

*Government transfers - extensive margin
capture drop __*
jwdid d_ritgxfr if ragey<63 & ragender==1 & c_lms_new==3 , ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-0.6 .2)) ylab(-0.6(.2).6) scale(1.3) 
graph export "$out_files/d_ritgxfr.pdf", replace

*Government transfers - intensive margin - exclude outlier with transfers of 999999 Euros
capture drop __*
jwdid ritgxfr_cpi if ragey<63 & ragender==1 & c_lms_new==3 & ritgxfr!=999999, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-15000 10000)) ylab(-10000(10000)30000) ylab(-10000 "-10" 0 "0" 10000 "10" 20000 "20" 30000 "30") scale(1.3) 
graph export "$out_files/ritgxfr_cpi.pdf", replace

*Government transfers - intensive margin - exclude top 1 percent
jwdid ritgxfr_cpi if ragey<63 & ragender==1 & c_lms_new==3 , ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
sum ritgxfr_cpi if e(sample), detail

scalar s_p99 = r(p99)
scalar list 

capture drop __*
jwdid ritgxfr_cpi if ragey<63 & ragender==1 & c_lms_new==3 & ritgxfr_cpi<s_p99, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-15000 10000)) ylab(-10000(10000)30000) ylab(-10000 "-10" 0 "0" 10000 "10" 20000 "20" 30000 "30") scale(1.3) 
graph export "$out_files/ritgxfr_cpi_99.pdf", replace

* Table D.1: Estimated effects of reaching the Early Retirement Age (ERA) on government transfers of unemployed men
qui jwdid d_ritgxfr if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo A
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: A
estadd matrix r_p1: A

qui jwdid d_ritgxfr if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo B
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: B
estadd matrix r_p1: B

qui jwdid ritgxfr_cpi if ragey<63 & ragender==1 & c_lms_new==3 & ritgxfr!=999999, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo C
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: C
estadd matrix r_p1: C

qui jwdid ritgxfr_cpi if ragey<63 & ragender==1 & c_lms_new==3 & ritgxfr!=999999, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo D
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: D
estadd matrix r_p1: D


jwdid ritgxfr_cpi if ragey<63 & ragender==1 & c_lms_new==3 , ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
sum ritgxfr_cpi if e(sample), detail

scalar s_p99 = r(p99)
scalar list 


qui jwdid ritgxfr_cpi if ragey<63 & ragender==1 & c_lms_new==3 & ritgxfr_cpi<s_p99, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo E
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: E
estadd matrix r_p1: E

qui jwdid ritgxfr_cpi if ragey<63 & ragender==1 & c_lms_new==3 & ritgxfr_cpi<s_p99, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
matrix b=e(b)
matrix colname b= "r3vs1._at"
erepost b=b, rename
eststo F
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
matrix colnames r_se1 = r3vs1._at
matrix colnames r_p1 = r3vs1._at
estadd matrix r_se1: F
estadd matrix r_p1: F

esttab A B C D E F using "$out_files/AppendixTableD1.tex", replace b(a2) se(a2) keep(r3vs1._at) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(r3vs1._at "ERA") cell(b(fmt(a2) star pvalue(r_p1)) r_se1(par)) collabels(none)

********************************************************************************
* Table D.2: Heterogeneity analysis of the effects of reaching the Early Retirement Age (ERA) on the mental well-being of men
********************************************************************************
sort nmergeid wave
bys nmergeid: gen wealth = hhatotn if _n==1
bys nmergeid: egen mean_wealth = mean(wealth)
bysort ragender isocountry c_lms_new: egen country_median=median(mean_wealth)
gen high = mean_wealth>=country_median

eststo clear
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3 & high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3 & high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo B

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3 & high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3 & high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo D

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==2 & high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo E

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==2 & high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo F

esttab A B C D E F using "$out_files/AppendixTableD2a.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA")

eststo clear
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3 & ~high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3 & ~high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo B

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3 & ~high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3 & ~high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo D

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==2 & ~high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo E

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==2 & ~high, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo F

esttab A B C D E F using "$out_files/AppendixTableD2b.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA")


********************************************************************************
* Table D.3 and Figure D.2: participation in social activities by unemployed men
********************************************************************************
*Table D.3: Estimated effects of reaching the Early Retirement Age (ERA) on participation in social activities by unemployed men
eststo clear
qui jwdid social_activities if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A

qui jwdid social_activities if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C

esttab A C using "$out_files/AppendixTableD3.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA")

*Figure D.2: Event study of participation in social activities by unemployed men
capture drop __*
qui jwdid social_activities if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
prepare_plot
coefplot, yline(0) xline(5.5, lc(cranberry)) baselevels omitted vert drop(r2vs1._at@2.__event__ r2vs1._at@20.__event__) keep(r*vs*) coeflabels(r2vs1._at@2.__event__ = "-11/-10" r2vs1._at@4.__event__ = "-9/-8"  r2vs1._at@6.__event__ = "-7/-6"  r2vs1._at@8.__event__ = "-5/-4" r2vs1._at@10.__event__ = "-3/-2" r2vs1._at@12.__event__ = "-1" r2vs1._at@14.__event__ = "0/1" r2vs1._at@16.__event__ = "2/3" r2vs1._at@18.__event__ = "4/5" r2vs1._at@20.__event__ = "6/7") ysc(r(-.4 .6)) ylab(-.4(.2).6) scale(1.3)
graph export "$out_files/act.pdf", replace


********************************************************************************
* Table E.1: Robustness tests
********************************************************************************
use "$working_data/sample1.dta", clear

bys nmergeid: egen tot = count(nmergeid)
gen emp = c_lms_new==2
bys nmergeid: egen tot_emp = sum(emp)
drop if tot_emp ~= tot & emp

// Panel a
eststo clear
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) cluster(isocountry) fevar(riwm)
estat simple, post
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
estadd matrix r_se1: A
estadd matrix r_p1: A

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo B
qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) cluster(isocountry) fevar(riwm)
estat simple, post
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
estadd matrix r_se1: B
estadd matrix r_p1: B

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never cluster(isocountry) fevar(riwm)
estat simple, post
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
estadd matrix r_se1: C
estadd matrix r_p1: C

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo D
qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never cluster(isocountry) fevar(riwm)
estat simple, post
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
estadd matrix r_se1: D
estadd matrix r_p1: D

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo E
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never cluster(isocountry) fevar(riwm)
estat simple, post
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
estadd matrix r_se1: E
estadd matrix r_p1: E

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo F
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never cluster(isocountry) fevar(riwm)
estat simple, post
matrix table1 = r(table)
matrix r_se1 = table1[2,1...]
matrix r_p1 = table1[4,1...]
estadd matrix r_se1: F
estadd matrix r_p1: F

esttab A B C D E F using "$out_files/AppendixTableE1a.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA") cell(b(fmt(a2)) se(par star) r_se1(par([ ]) star pvalue(r_p1))) collabels(none)

// Panel b
preserve
drop if isocountry == 528
drop if isocountry == 380

eststo clear
qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo B

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo D

qui jwdid depression if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo E

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_new==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo F

esttab A B C D E F using "$out_files/AppendixTableE1b.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA")

********************************************************************************
* Panel c - LMS Definition - Robustness: Other group allocated to (1) retired, (2) disabled, or (3) unemployed
********************************************************************************
restore

*Construct using 4 attributes
gen c_lms_robust = .
*Retired
replace c_lms_robust = 1 if d_ret_inc==1 

*Employed
replace c_lms_robust = 2 if d_ret_inc==0 & d_di_inc==0 & d_earn_inc==1 & d_works_10==1

*Unemployed
replace c_lms_robust = 3 if d_ret_inc==0 & d_di_inc==0 & d_earn_inc==0 & d_works_10==0 //& work_hours!=. & work_hours!=.d & work_hours!=.m & work_hours!=.r 
replace c_lms_robust = 3 if d_ret_inc==0 & d_di_inc==0 & d_earn_inc==1 & d_works_10==0 //& work_hours!=. & work_hours!=.d & work_hours!=.m & work_hours!=.r 
replace c_lms_robust = 3 if d_ret_inc==0 & d_di_inc==0 & d_earn_inc==0 & d_works_10==1 //& work_hours!=. & work_hours!=.d & work_hours!=.m & work_hours!=.r 

*Disabled
replace c_lms_robust = 4 if d_ret_inc==0 & d_di_inc==1 & d_earn_inc==0 & d_works_10==0 //& work_hours!=. & work_hours!=.d & work_hours!=.m & work_hours!=.r 
replace c_lms_robust = 4 if d_ret_inc==0 & d_di_inc==1 & d_earn_inc==1 & d_works_10==0 //& work_hours!=. & work_hours!=.d & work_hours!=.m & work_hours!=.r 
replace c_lms_robust = 4 if d_ret_inc==0 & d_di_inc==1 & d_earn_inc==0 & d_works_10==1 //& work_hours!=. & work_hours!=.d & work_hours!=.m & work_hours!=.r 
replace c_lms_robust = 4 if d_ret_inc==0 & d_di_inc==1 & d_earn_inc==1 & d_works_10==1 //& work_hours!=. & work_hours!=.d & work_hours!=.m & work_hours!=.r 

label define c_lms_robust_label 1 "Retired" 2 "Employed" 3 "Unemployed" 4 "Disabled" 
label value c_lms_robust c_lms_robust_label
	
tab c_lms_robust if ragender==1 & inrange(ragey, 50, 70)
tab c_lms_new if ragender==1 & inrange(ragey, 50, 70)
tab c_lms_new c_lms_robust if ragender==1 & inrange(ragey, 50, 70)

eststo clear
qui jwdid depression if ragey<63 & ragender==1 & c_lms_robust==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo A

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_robust==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo B

qui jwdid depression if ragey<63 & ragender==1 & c_lms_robust==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo C

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_robust==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo D

qui jwdid depression if ragey<63 & ragender==1 & c_lms_robust==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo E

qui jwdid reurod if ragey<63 & ragender==1 & c_lms_robust==2, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
local obs = e(N_full)
estadd ysumm
local ymean = e(ymean)
estat simple, post
estadd scalar obs= `obs'
estadd scalar ymean = `ymean'
eststo F

esttab A B C D E F using "$out_files/AppendixTableE1c.tex", replace b(a2) se(a2) keep(simple) label nolines noobs nogaps nomtitles compress fragment nonumbers mlabels(none) stats(ymean obs, labels("Mean Outcome" "Observations")) starlevels(* 0.10 ** 0.05 *** 0.01) coeflabels(simple "ERA")


********************************************************************************
* Robustness - sensitivity to EURO-D cutoff - only reported in text
********************************************************************************
gen depression3 = reurod>=3 & reurod!=.

jwdid depression3 if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
estat simple

jwdid depression3 if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
estat simple

gen depression5 = reurod>=5 & reurod!=.

jwdid depression5 if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) fevar(riwm)
estat simple

jwdid depression5 if ragey<63 & ragender==1 & c_lms_new==3, ivar(nmergeid) tvar(ragey) gvar(group_eray_never) never fevar(riwm)
estat simple


********************************************************************************







